<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>BB量化交易系统-注册</title>
	<link rel="icon" href="/static/images/bb-32.ico" type="image/x-icon" />
	<link rel="shortcut icon" href="/static/images/bb-32.ico" type="image/x-icon"/>
	<link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/icon.css">
	<!-- <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/demo/demo.css"> -->
	<script type="text/javascript" src="/static/plugins/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="/static/plugins/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/static/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="background:url(/static/images/bg3.jpg);background-size:cover">
    <div id="registerForm" class="easyui-window" title="注册" data-options="modal:true,collapsible:false,shadow:true,closed:false,iconCls:'Lockgo',closable:false,minimizable:false" style="width:500px;padding:20px 70px 20px 70px;background:url(/static/images/bg.jpg)center;background-size:cover">
    	<div >
    		<h1 style="text-align:center;color:#fff">注   册 </h1>
    	</div>
        <div id="input_email" style="margin:40px 0 40px 0">
            <input class="easyui-textbox" id="email" name="email" type="text" style="width:100%;height:30px;padding:12px" data-options="prompt:'邮箱',iconCls:'icon-man',iconWidth:38">
        </div>
         <div id="input_code" style="margin:40px 0 40px 0;display:none" >
            <input class="easyui-textbox"  name="code" type="text" style="width:100%;height:30px;padding:12px" data-options="prompt:'验证码',iconCls:'icon-lock',iconWidth:38">
        </div>
        <div id="input_password" style="margin:40px 0 40px 0;display:none">
            <input class="easyui-textbox" name="password" type="password" style="width:100%;height:30px;padding:12px" data-options="prompt:'密   码',iconCls:'icon-lock',iconWidth:38">
        </div>
        <div id="input_enPassword" style="margin:40px 0 40px 0;display:none">
            <input class="easyui-textbox" name="enPassword" type="password" style="width:100%;height:30px;padding:12px" data-options="prompt:'确认密码',iconCls:'icon-lock',iconWidth:38">
        </div>
        
        <div id="btn_sendCode" style="margin:40px 0 40px 0">
            <a href="javascript:;" onclick="sendCode()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="padding:5px 0px;width:100%;">
                <span style="font-size:14px;">发送验证码到邮箱</span>
            </a>
        </div>
        <div id="btn_submit" style="margin:40px 0 40px 0;display:none">
            <a href="javascript:;" onclick="submit()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="padding:5px 0px;width:100%;">
                <span style="font-size:14px;">提交</span>
            </a>
        </div>
         <div id="btn_re_sendCode" style="margin:40px 0 40px 0;display:none">
            <a href="javascript:;" onclick="sendCode()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="padding:5px 0px;width:100%;">
                <span style="font-size:14px;">重新发送验证码</span>
            </a>
        </div>
        <div id="btn_register"style="margin:40px 0 40px 0;display:none">
            <a href="javascript:;" onclick="doRegister()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="padding:5px 0px;width:100%;">
                <span style="font-size:14px;">注册</span>
            </a>
        </div>
        <div  style="margin:40px 0 40px 0;">
            <a href="./login" style="color:#fff">用已有账号登录</a>
        </div>
</div>

</body>
<script type="text/javascript">

function sendCode(){
	var patt = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/g;
	var email = $("input[name='email']").val();
	var boo = patt.test(email)
	if(boo){
		$.messager.progress({title:'请稍候',msg:'验证码正在发送中...'});
		$.post('./user/sendCode',{"email":email},function(res){
			$.messager.progress('close');
			if(res.status == 200){
				$("#registerForm").data("email",email);
				$("#email").textbox({disabled:true});//禁用;
				$("#input_code").show();
				$("#btn_sendCode").hide();
				$("#btn_submit").show();
				$("#btn_re_sendCode").show();
				$.parser.parse();
			}else{
				$.messager.alert('提示',res.message,'info');
			}
		})
	}else{
		$.messager.alert('错误','请输入一个正确的邮箱','error');
	}
	
	
}

function doRegister(){
	var email = $("#registerForm").data("email");
	var password = $("input[name='password']").val() || '';
	var enPassword = $("input[name='enPassword']").val();
	if(password.length < 8 ){
		$.messager.alert('错误','密码至少为8位','error');
		return;
	}
	if(password != enPassword){
		$.messager.alert('错误','两次密码输入不一致！','error');
	}else{
		$.messager.progress({title:'请稍候',msg:'正在注册...'});
		$.post("./user/register",{"email":email,"password":password},function(res){
			$.messager.progress('close');
			if(res.status == 200){
				$("#registerForm").removeData();
				window.location.href="/login";
			}else{
				$.messager.alert('提示',res.message,'info');
			}
		})
	}
	
}
function submit(){
	var email = $("#registerForm").data("email");
	var code = $("input[name='code']").val();
	$.messager.progress({title:'请稍候',msg:'正在提交...'});
	$.post("./user/verifyCode",{"email":email,"code":code},function(res){
		$.messager.progress('close');
		if(res.status == 200){
			$("#input_code").hide();
			$("#input_password").show();
			$("#input_enPassword").show();
			$("#btn_submit").hide();
			$("#btn_re_sendCode").hide();
			$("#btn_register").show();
			$.parser.parse();
		}else{
			$.messager.alert('提示',res.message,'info');
		}
	})
}
</script>
</html>